// const twoWayEnum = (obj) => {
//   /**
//    * @param {Record<PropertyKey, PropertyKey>} obj - The object to convert to a two-way enum.
//    */
//   const newObj = {};
//   for (const key in obj) {
//     newObj[key] = obj[key];
//     newObj[obj[key]] = key;
//   }
//   return newObj;
// }

class TwoWayEnum {
  /**
   * @public
   */
  static instance = new TwoWayEnum();

  /**
   * @private
   * @type {Record<PropertyKey, PropertyKey>}
   */
  constructor(obj = {}) {
    Object.assign(this, obj);
    // eslint-disable-next-line no-constructor-return
    return new Proxy(this, {
      set(target, property, value, receiver) {
        if (
          typeof value === "number" ||
          typeof value === "string" ||
          typeof value === "symbol"
        ) {
          return (
            Reflect.set(target, property, value, receiver),
            Reflect.set(target, value, property, receiver)
          );
        }
        console.warn(
          `[twoWayEnum] value must be number, string or symbol, got ${Object.prototype.toString.call(value)}`,
        );
        return false;
      },
    });
  }
}

export default TwoWayEnum.instance;
